package com.gitee.magic.jdbc.spring.schema;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

import com.gitee.magic.jdbc.persistence.source.jdbc.mapper.MapperManager;

/**
 * @author start
 */
public class ConfigBeanDefinitionParser implements BeanDefinitionParser {

	private static final String BASE_PACKAGE_ATTRIBUTE = "mapper-package";
	
	@Override
	public BeanDefinition parse(Element element, ParserContext parserContext) {
		
		String basePackage = element.getAttribute(BASE_PACKAGE_ATTRIBUTE);
		basePackage = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(basePackage);
		String[] basePackages = StringUtils.tokenizeToStringArray(basePackage,
				ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
		
		MapperManager manager=new MapperManager();
		manager.start(basePackages);
		
		return null;
	}

}
